//
//  WHYTabBarViewController.m
//  News163
//
//  Created by 王洪运 on 15/12/29.
//  Copyright © 2015年 王洪运. All rights reserved.
//

#import "WHYTabBarViewController.h"
#import "WHYNavigationViewController.h"

#import "WHYMainViewController.h"
#import "WHYDiscoverViewController.h"
#import "WHYReadingViewController.h"
#import "WHYMeViewController.h"
#import "WHYVideoViewController.h"

#import "WHYBottomTabBar.h"

@interface WHYTabBarViewController ()<WHYBottomTabBarDelegate>

@end

@implementation WHYTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupSubViewControllers];
    
    [self setupCustomTabBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 初始化子控制器
-(void)setupSubViewControllers {
    
    WHYNavigationViewController *mainNav = [WHYNavigationViewController navigetionControllerWithStoryboardName:@"Main"];
    
    WHYNavigationViewController *readingNav = [WHYNavigationViewController navigetionControllerWithStoryboardName:@"Reading"];
    
    WHYNavigationViewController *videoverNav = [WHYNavigationViewController navigetionControllerWithStoryboardName:@"Video"];
    
    WHYNavigationViewController *discoverNav = [WHYNavigationViewController navigetionControllerWithStoryboardName:@"Discover"];
    
    WHYNavigationViewController *meNav = [WHYNavigationViewController navigetionControllerWithStoryboardName:@"Me"];
    
    self.viewControllers = @[mainNav, readingNav, videoverNav, discoverNav, meNav];
}



#pragma mark - 初始化自定义tabBar
-(void)setupCustomTabBar {
    
    WHYBottomTabBar *tabBar = [[WHYBottomTabBar alloc] init];
    
    NSUInteger count = self.viewControllers.count;
    
    for (int i = 0; i < count; i++) {
        
        NSString *normal = [NSString stringWithFormat:@"TabBar%zd",i + 1];
        NSString *selected = [NSString stringWithFormat:@"TabBar%zdSel",i + 1];
        
        [tabBar addBottomTabBarButtonWithNormalImageName:normal selectedImageName:selected];
        
    }
    
    tabBar.frame = self.tabBar.bounds;
    [self.tabBar addSubview:tabBar];
    
    tabBar.delegate = self;
    
}

#pragma mark - WHYBottomTabBarDelegate
-(void)bottomTabBar:(WHYBottomTabBar *)bottomTabBar didClickTabBarButtonWithIndex:(NSInteger)index {
    
    self.selectedIndex = index;
    
}

@end












